package com.officegame.db.implementation.hibernate;

import java.io.File;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import com.officegame.db.entities.Game;
import com.officegame.db.entities.Player;
import com.officegame.db.entities.Team;

@SuppressWarnings("deprecation")
public class HibernateUtil {

	private static final SessionFactory sessionFactory;

	static {
		try {
			AnnotationConfiguration config = new AnnotationConfiguration().configure(new File("hibernate.cfg.xml"));
			config.addAnnotatedClass(Player.class);
			config.addAnnotatedClass(Team.class);
			config.addAnnotatedClass(Game.class);
			sessionFactory = config.buildSessionFactory();
		} catch (Throwable ex) {
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static Session getSession()
			throws HibernateException {
		return sessionFactory.openSession();
	}
}	